Wiki

Clone wiki

Rug.Osc / Parsing messages and bundles from strings

With Rug.Osc any osc message or bundle can be parsed from a string and conversely calling the ToString method on any message or bundle will result in a string that is compatible with parsing.

Message format

The format of osc messages consists of a osc-address optionally followed by a csv of argument values. There is no need to include the osc typetag in the string as it is derived from the types of the parsed arguments.

#!text
With no arguments
/foo

With arguments
/bar, 1, 2.3f, 4, 5, 6, "string", true

Bundle format

Bundles are prefixed with the "#bundle" identifier followed by a osc-timetag then a csv of osc-packets (messages or bundles. Each osc-packet must be surrounded with curly braces "{ .. }".

#!text
#bundle, 23-08-2013 01:00:34.3530Z, { /foo, 42 }, { /bar, 1, 2, 3 }

Parsing osc messages, bundles and packets

To explicitly parse a osc message from a string call the static Parse, TryParse or any of the overrides.

#!c#

OscMessage parsed = OscMessage.Parse("/foo, 1, 2, 3, 4, 5, \"This is a string\"");

To explicitly parse a osc bundle from a string call the static Parse, TryParse or any of the overrides.

#!c#

OscBundle parsed = OscBundle.Parse("#bundle, 23-08-2013 01:00:34.3530Z, { /foo, 42 }");

Or you can parse a osc packet directly.

#!c#

OscPacket parsed1 = OscPacket.Parse("/foo, 1, 2, 3, 4, 5, \"This is a string\"");
OscPacket parsed2 = OscPacket.Parse("#bundle, 23-08-2013 01:00:34.3530Z, { /foo, 42 }");

Examples

Listed below are examples of valid message and bundle strings for various argument types.

#!text
Integer (Int32)
/foo, 42
/foo, 0x2A


Long (Int64)
/foo, 12334L
/foo, 0x13C1DA49E6B50B0F


Float (Single)
/foo, 123.34
/foo, 123.34f
/foo, 123.45e+6 
/foo, +500
/foo, 5e2
/foo, 600.
/foo, -.123
/foo, -Infinity
/foo, -1E-16


Double
/foo, 123.34d


String
/foo, "string"


Symbol
/foo, SymbolString


Bool (Boolean)
/foo, true
/foo, false


Color (ARGB)
/foo, { Color: Red }
/foo, { Color: 255, 255, 0, 255 }


Osc-Null
/foo, null
/foo, nil


Osc-Timetag
/foo, { Time: 00:00:34.3532Z }
/foo, { Time: 0x13C1DA49E6B50B0F }
/foo, { Time: 1234 }

Additionally any of these datetime formats can be used. 
"dd-MM-yy"
"dd-MM-yyyy"
"HH:mm"
"HH:mm:ss"
"HH:mm:ss.ffff"
"dd-MM-yyyy HH:mm:ss"
"dd-MM-yyyy HH:mm"
"dd-MM-yyyy HH:mm:ss.ffff" 

Any of these can be postfixed with a 'Z' to indicate that the time should be interpreted as UTC rather than local time.


Osc-Impulse / Infinitum
/foo, infinitum
/foo, impulse
/foo, bang


Char (byte)
/foo, 'Q'


Blob (byte array)
/foo, { Blob: 1, 2, 3, 4 } 
/foo, { Blob: 0x01020304 } 
/foo, { Blob: 64xAQIDBA== } 


Array
/foo, [ 1, 2, 3, 4 ]


Bundles
#bundle, 23-08-2013 01:00:34.3530Z, { /foo, 42 }

Updated